home *** CD-ROM | disk | FTP | other *** search
-
- #include "EventLog.h"
- #include <PLStringFuncs.h>
- #include <Files.h>
- #include <Events.h>
- #include <string.h>
-
-
- short logRefNum;
-
- static Boolean FormatOSEvent (EventRecord* event, char* str);
-
-
- void EventLog_StartLog(FSSpec* spec, Boolean flushLog)
- {
- FSSpec logSpec;
- FInfo ignore;
-
- if (spec == NULL)
- {
- PLstrcpy (logSpec.name, "\pCASample Event Log");
- logSpec.vRefNum = 0;
- logSpec.parID = 2;
- }
- else
- {
- logSpec = *spec;
- }
-
- if (FSpGetFInfo (&logSpec, &ignore))
- {
- FSpCreate (&logSpec, 'ttxt', 'TEXT', 0);
- }
-
- FSpOpenDF (&logSpec, fsRdWrPerm, &logRefNum);
-
- if (flushLog)
- SetEOF (logRefNum, 0);
-
- }
-
-
-
- void EventLog_StopLog()
- {
- FSClose (logRefNum);
- }
-
- void EventLog_PrintComment (char* comment)
- {
- long count;
- char eol[2];
-
- count = strlen (comment) + 1;
-
- FSWrite (logRefNum, &count, comment);
-
- count = 1;
- eol[0] = 0x0D;
- FSWrite (logRefNum, &count, eol);
-
- }
-
- void EventLog_PrintEvent (EventRecord* event)
- {
- char str[128];
- Str32 messg;
- char eol[2];
- long count;
- Boolean printIt = true;
-
- NumToString (event->message, messg);
-
- switch (event->what)
- {
-
- case diskEvt:
- strcpy(str, "diskEvt\t\t"); break;
-
- case activateEvt:
- strcpy(str, "activateEvt\t"); break;
-
- case kHighLevelEvent:
- strcpy(str, "kHighLevelEvent\t"); break;
-
- case mouseDown:
- strcpy(str, "mouseDown\t\t"); break;
-
- case mouseUp:
- strcpy(str, "mouseUp\t\t"); break;
-
- case updateEvt:
- strcpy(str, "updateEvt\t\t"); break;
-
- case keyDown:
- strcpy(str, "keyDown\t\t"); break;
-
- case nullEvent:
- strcpy(str, "nullEvent\t\t"); break;
-
- case osEvt:
- printIt = FormatOSEvent (event, str); break;
-
- case autoKey:
- strcpy(str, "autoKey\t\t"); break;
-
- case keyUp:
- strcpy(str, "keyUp\t\t"); break;
-
- default:
- strcpy(str, "UNKNOWN event"); break;
- }
-
-
- //strncat (str, (char*) &messg[1], (short) messg[0]);
- //strcat (str, "");
-
- if (printIt)
- {
-
- count = strlen (str) + 1;
- FSWrite (logRefNum, &count, str);
- count = 1;
- eol[0] = 0x0D;
- FSWrite (logRefNum, &count, eol);
-
- }
-
- }
-
-
- static Boolean FormatOSEvent (EventRecord* event, char* str)
- {
- Boolean isSuspendEvent;
-
- switch ((event->message >> 24) & 0x0FF)
- {
- case mouseMovedMessage:
- return false;
-
- case suspendResumeMessage:
-
- if (isSuspendEvent)
- strcpy(str, "osEvt\t\tSuspend");
- else
- strcpy(str, "osEvt\t\tResumt");
- return true;
-
- default:
- break;
-
- }
-
- return false;
-
- }